@extends('user.layouts.layout')
@section('title', '发起提现')

@section('content')
    <div class="mx-auto md:w-1/3 w-full bg-white rounded-lg p-6">
        <div class="bg-blue-100 rounded-md py-3 px-2 mb-3">
            当前可提现余额：<span class="text-xl text-red-500">{{ $merchant->balance - $merchant->frozen_balance }}</span> 冻结金额：<span class="text-xl text-red-500">{{ $merchant->frozen_balance }}</span>
        </div>
        <div class="">
            <h6>请确认提现信息</h6>
            <ul>
                <li class="text-xs my-2 flex items-center">
                    <span class="w-18 text-gray-400">提现方式：</span>
                    <span>{{ \App\Models\CashInfo::$cashTypeMap[$info->cash_type]}}</span>
                </li>
                <li class="text-xs my-2 flex items-center">
                    <span class="w-18 text-gray-400">真实姓名：</span>
                    <span>{{ $info->realname }}</span>
                </li>
                <li class="text-xs my-2 flex items-center">
                    <span class="w-18 text-gray-400">提现账号：</span>
                    <span>{{ $info->account }}</span>
                </li>
            </ul>
        </div>
        <hr>
        <form action="{{ route('user.merchants.cashdraw', ['merchant' => $merchant->id]) }}" method="POST" id="cash-form">
            {{ csrf_field() }}
            <div class="block mt-2">
                <span class="text-gray-700 text-sm">提现金额</span>
                <div class="relative">
                    <a href="javascript:void(0);" data-amount="{{ $merchant->balance - $merchant->frozen_balance }}" id="all" class="absolute inset-y-0 right-3 text-indigo-600 flex items-center width">全部</a>
                    <input type="text" name="amount" id="amount" value="0.00" class="form-input w-full mt-1 rounded-md focus:border-indigo-600">
                </div>
                @error('amount')
                <p class="mt-2 text-sm text-red-600">{{ $message }}</p>
                @enderror
            </div>
            <div class="block mt-2">
                <span class="text-gray-700 text-sm">提现金额</span>
                <textarea name="remark" class="form-textarea mt-1 block w-full" rows="3" placeholder="备注... 200个字以内"></textarea>
                @error('remark')
                <p class="mt-2 text-sm text-red-600">{{ $message }}</p>
                @enderror
            </div>
            <div class="mt-6">
                <button class="py-3 px-4 text-center bg-indigo-600 rounded-md w-full text-white text-sm hover:bg-indigo-500" id="sub">
                    提交
                </button>
            </div>
        </form>
    </div>
@endsection
@section('afterScript')
    <script>
        (function () {
            $('#all').click(function () {
                $('#amount').val($(this).data('amount'))
            });

            $('#cash-form').on('submit', function () {
                var inputAmount = $('#amount').val();
                if (inputAmount <= 0) {
                    $.message({message:"请输入提现金额", type:"error"});
                    return false;
                }
                if (inputAmount > '{{ $merchant->balance - $merchant->frozen_balance }}') {
                    $.message({message:"超出最大可提现金额", type:"error"});
                    return false;
                }
            });
        })();
    </script>
@endsection
